package com.ruoyi.module.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.module.mapper.MaterialMapper;
import com.ruoyi.module.domain.Material;
import com.ruoyi.module.service.IMaterialService;

/**
 * 素材库内容Service业务层处理
 *
 * @author fubojin
 * @date 2025-03-01
 */
@Service
public class MaterialServiceImpl implements IMaterialService
{
    @Autowired
    private MaterialMapper materialMapper;

    /**
     * 查询素材库内容
     *
     * @param id 素材库内容主键
     * @return 素材库内容
     */
    @Override
    public Material selectMaterialById(Long id) {
        Material material = materialMapper.selectMaterialById(id);
        material.setSort(material.getSort()==null?1:material.getSort()+1);
        materialMapper.updateMaterial(material);
        return material;
    }

    /**
     * 查询素材库内容列表
     *
     * @param material 素材库内容
     * @return 素材库内容
     */
    @Override
    public List<Material> selectMaterialList(Material material)
    {
        return materialMapper.selectMaterialList(material);
    }

    /**
     * 新增素材库内容
     *
     * @param material 素材库内容
     * @return 结果
     */
    @Override
    public int insertMaterial(Material material)
    {
        material.setCreateTime(DateUtils.getNowDate());
//        material.setAuditStatus(1);
        return materialMapper.insertMaterial(material);
    }

    /**
     * 修改素材库内容
     *
     * @param material 素材库内容
     * @return 结果
     */
    @Override
    public int updateMaterial(Material material)
    {
        material.setUpdateTime(DateUtils.getNowDate());
        return materialMapper.updateMaterial(material);
    }

    /**
     * 批量删除素材库内容
     *
     * @param ids 需要删除的素材库内容主键
     * @return 结果
     */
    @Override
    public int deleteMaterialByIds(Long[] ids)
    {
        return materialMapper.deleteMaterialByIds(ids);
    }

    /**
     * 删除素材库内容信息
     *
     * @param id 素材库内容主键
     * @return 结果
     */
    @Override
    public int deleteMaterialById(Long id)
    {
        return materialMapper.deleteMaterialById(id);
    }
}
